﻿/**
 * 
 * Copyright 2009, 2010 Mike Jamer [email: mikejamer@gmail.com ]
 * 
 * This File is part of Moose IRC
 * 
 * MooseIRC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * MooseIRC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with MooseIRC.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using moose.extension;
using moose.irc;

namespace moose.irc.standard.actions
{
    /// <summary>
    /// Handles Channel Mode Responses
    /// </summary>
    public sealed class ModeResponse : IrcAction
    {
        public override IrcSessionStates valid_states()
        {
            return IrcSessionStates.Registered;
        }

        public override void action(IrcSession session, IrcMessage message)
        {
            //First grab channel we are getting arguments for
            IrcChannel channel = (IrcChannel)session.get_entity(message.Arguments[0]);

            //Build mode string out of arguments
            StringBuilder sbModeString = new StringBuilder();
            for (int i = 1; i < message.Arguments.Length; i++)
            {
                sbModeString.Append(message.Arguments[i]);
                sbModeString.Append(' ');
            }
            //Update Mode String
            channel.update_modes(sbModeString.ToString());

            //Print Mode change to status window
            session.notify_event(
            IrcEvent.createEchoEvent(
                    "Mode: " + channel.Name + sbModeString.ToString()
                ));

            return;
        }
    }
}
